package nix.demo8.dao;

import java.sql.SQLException;
import java.util.List;

import nix.demo8.domain.City;
import nix.demo8.domain.Province;
import nix.jdbc.TxQueryRunner;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class Dao {

	private QueryRunner qr = new TxQueryRunner();

	public List<Province> findAllProvince() {
		try {
			return qr.query("select * from t_province",
					new BeanListHandler<Province>(Province.class));
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public List<City> findByProvince(int pid) {
		try {
			return qr.query("select * from t_city where pid = ?",
					new BeanListHandler<City>(City.class), pid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}
